<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">叫货审核</div>
      </div>
 
        <!--  -->
        <div class="">
          <template>
            <el-table :data="tabledata" @cell-click="gotrainpro">
              <el-table-column label="品名" width="90" fixed>
                <template slot-scope="scope">
                  {{scope.row.title}}
                </template>
              </el-table-column>
              <el-table-column label="存规格" width="">
                <template slot-scope="scope">
                  {{scope.row.save_unit}}
                </template>
              </el-table-column>
              <el-table-column label="计划量" width="">
                <template slot-scope="scope">
                  {{scope.row.plan_num}}
                </template>
              </el-table-column>
              <el-table-column label="叫货量" width="">
                <template slot-scope="scope">
                    {{scope.row.buy_num}}
                </template>
              </el-table-column>
              <el-table-column label="审核量" width="130">
                <template slot-scope="scope">
                  <div v-if="thstate=='1'" style="border:1px solid #058142;border-radius:.2rem;"><el-input v-model="scope.row.check_num" placeholder="请输入内容" type="number"></el-input></div>
                  <div v-else>
                    {{scope.row.check_num}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="单价" width="">
                <template slot-scope="scope">
                  {{scope.row.unit_price}}
                </template>
              </el-table-column>
              <el-table-column label="金额" width="">
                <template slot-scope="scope">
                  {{(scope.row.check_num*scope.row.unit_price).toFixed(2)}}
                </template>
              </el-table-column>
            </el-table>
          </template>
          <div class="x-table-desc">叫货人：{{askname}}</div>
          <div class="x-table-desc">审核人：{{checkname}}</div>
        </div>
        <!--  -->
        <div class="x-pro-gobtn" @click="isok" v-if="thstate==1">审核</div>
        <div class="x-pro-gobtn x-disabled" v-else>已审核</div>
		
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/jquery-1.11.1.min.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    var tid = api.pageParam.id;
    var tstate = api.pageParam.state;

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:'',
          curId:0,
          tabledata:[],
          cardsmonth:'',
          cardsmonthtoy:'',
          cardsmonthtom:'',
          tabsid:0,
          notkey:false,
          isfromindex:true,
          askname:'',
          yesshow:false,
          noshow:false,
          checkname:'',
          thid:'',
          thstate:0,
          isclick:true,
        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.thid = tid;
        that.thstate = tstate;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        var day = date.getDate();
        if(month<10){
          month = '' + 0 + month;
        }
        if(day<10){
          day = '' + 0 + day;
        }
        var toMonth = '' + year + month + day;
        that.cardsmonth = toMonth;
        that.cardsmonthtoy = year;
        that.cardsmonthtom = month;
        that.gettrainadmin()
      },
      methods: {
        //提交
        isok:function(){
          let that=this;
          if(that.isclick){
            that.isclick = false
            api.ajax({
              url:baseurl+'api/material/addCheck?sec=' + $api.getStorage('apptoken') + '&id=' + that.thid,
              method:'post',
              data:{
                values:{
                  num_json:that.tabledata
                }
              }
            },function(ret,err){
              if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                  that.gettrainadmin()
                  that.thstate = 2;
                }else{
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                }
              }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            })
          }
          
        },
        //切换选择日期
        getmonth:function(val){
          var that = this;
          // console.log(val);
          // console.log(val.getMonth()+1);
          // var tmon = val.getMonth()+1
          // if(tmon<10){
          //   tmon=''+0+tmon
          // }
          // console.log(''+val.getFullYear() + tmon);
          that.cardsmonth = val;
          that.cardsmonthtoy = that.cardsmonth.slice(0,4);
          that.cardsmonthtom = that.cardsmonth.slice(4,6);
          that.gettrainadmin()

        },
        //点击列
        gotrainpro:function(val){
          // console.log(JSON.stringify(val));
          // api.openWin({
          //     name: 'intraindesc',
          //     url: './intraindesc.html',
          //     pageParam: {
          //         id: val.id,
          //         levelid:val.up_levelid
          //     }
          // });
        },
        //切换选项卡 表格数据
        changetab:function(index,id){
          var that = this;
          that.curId = index;
          that.tabsid = id;
          that.gettrainadmin()
      		// mySwiper.slideToLoop(index, 500, false);
        },
        //表格data
        gettrainadmin:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/checkDetail',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.thid
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){

                  that.tabledata = ret.data.list;

             
                  // if(that.thstate=='1'){//没审核
                  //   console.log('000');
                  //   for(var i=0;i<that.tabledata.length;i++){
                  //     that.tabledata[i].check_num = that.tabledata[i].buy_num;
                  //   }
                  // }
                  that.askname = ret.data.buy_username;
                  that.checkname = ret.data.check_username;

              }else if(ret.status == 0){
                that.tabledata = [];
                
                that.askname = '';
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}

	</script>
</body>
</html>
